package org.example.myleet.p559;

import org.example.myleet.model.Node;

import java.util.LinkedList;
import java.util.Queue;

public class Solution {
    public int maxDepth(Node root) {
        if (null == root) {
            return 0;
        }
        int depth = 0;
        Queue<Node> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            int len = queue.size();
            for (int i = 0; i < len; ++i) {
                Node cur = queue.poll();
                if (null != cur.children) {
                    for (Node child : cur.children) {
                        queue.offer(child);
                    }
                }
            }
            ++depth;
        }
        return depth;
    }
}
